package com.mainworks.template.controller.security;

import com.mainworks.commons.UnifyResponse;
import com.mainworks.commons.utils.ParamsValidator;
import com.mainworks.template.params.LoginParams;
import com.mainworks.template.service.security.UserLoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

/**
 * 用户登录控制器
 * @Author: HuangMinJie
 * @CreateDate: 2021/10/31 15:24
 * @Description:
 * @Version: 1.0.0.0
 * @ModifiedBy:
 * @ModifiedDate:
 * @ModifiedDescription:
 */
@RestController
public class UserLoginController {
    @Autowired
    private UserLoginService userLoginService;

    @PostMapping("/user/login")
    public UnifyResponse login(@Valid @RequestBody(required = false)LoginParams params, BindingResult result, HttpServletRequest request){
        ParamsValidator.paramsNotNull(params);
        ParamsValidator.validate(result);
        UnifyResponse object = userLoginService.login(params,request);
        return object;
    }
}
